package com.esri.core.tasks.geodatabase;

import com.esri.core.internal.util.d;
import java.io.IOException;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Iterator;
import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.JsonGenerator;
import org.codehaus.jackson.JsonParser;
import org.codehaus.jackson.JsonToken;

/* loaded from: classes.dex */
public class LayerSyncInfos extends ArrayList<LayerSyncInfo> {
    private static final long serialVersionUID = 1;

    public String toJson() throws IOException {
        return toJsonInternal(false);
    }

    public static LayerSyncInfos fromJson(JsonParser jsonParser) throws Exception {
        LayerSyncInfos layerSyncInfos = new LayerSyncInfos();
        while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
            layerSyncInfos.add(LayerSyncInfo.fromJson(jsonParser));
        }
        return layerSyncInfos;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public String toJsonForRest() throws JsonGenerationException, IOException {
        return toJsonInternal(true);
    }

    private String toJsonInternal(boolean z) throws JsonGenerationException, IOException {
        JsonGenerator jsonGenerator;
        StringWriter stringWriter = new StringWriter();
        try {
            jsonGenerator = d.a(stringWriter);
        } catch (Throwable th) {
            th = th;
            jsonGenerator = null;
        }
        try {
            jsonGenerator.writeStartArray();
            Iterator<LayerSyncInfo> it = iterator();
            while (it.hasNext()) {
                LayerSyncInfo next = it.next();
                if (!z || next.getSyncDirection() != SyncDirection.NONE) {
                    next.toJson(jsonGenerator);
                }
            }
            jsonGenerator.writeEndArray();
            if (jsonGenerator != null) {
                try {
                    jsonGenerator.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return stringWriter.toString();
        } catch (Throwable th2) {
            th = th2;
            if (jsonGenerator != null) {
                try {
                    jsonGenerator.close();
                } catch (IOException e2) {
                    e2.printStackTrace();
                }
            }
            throw th;
        }
    }
}
